<!DOCTYPE html>
<html>
<head>
    <meta charset="utf-8">
    <title>质量验收记录</title>
    <meta name="renderer" content="webkit">
    <meta http-equiv="X-UA-Compatible" content="IE=edge,chrome=1">
    <meta name="viewport" content="width=device-width, initial-scale=1, maximum-scale=1">
    <link rel="stylesheet" href="/lib/layui/css/layui.css">
    <link rel="stylesheet" href="/static/css/weadmin.css">
    <script type="text/javascript" src="/templates/act/process-xl.js"></script>
    <!-- 注意：如果你直接复制所有代码到本地，上述css路径需要改成你本地的 -->
</head>
<body>
<form class="layui-form searchForm" action="">

    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">所在区域：</label>
            <div class="layui-input-inline" style="width: 120px;">
                <select lay-search  name="cityNum" id="cityNum" autocomplete="off" class="layui-input" lay-filter="cityChange">
                    <option value="">请选择</option>
                    <option value="130100">石家庄市</option>
                    <option value="130200">唐山市</option>
                    <option value="130300">秦皇岛市</option>
                    <option value="130400">邯郸市</option>
                    <option value="130500">邢台市</option>
                    <option value="130600">保定市</option>
                    <option value="130700">张家口市</option>
                    <option value="130800">承德市</option>
                    <option value="130900">沧州市</option>
                    <option value="131000">廊坊市</option>
                    <option value="131100">衡水市</option>
                </select>
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 120px;">
                <select lay-search  name="countyNum" id="countyNum" autocomplete="off" class="layui-input">
                    <option value="">请选择</option>
                </select>
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">项目名称：</label>
            <div class="layui-input-inline">
                <input name="prjName" id="prjName" placeholder="请输入项目名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">施工单位：</label>
            <div class="layui-input-inline">
                <input name="sgCorpName" id="sgCorpName" placeholder="请输入企业名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <div class="layui-inline">
            <label class="layui-form-label">建设单位：</label>
            <div class="layui-input-inline">
                <input name="buildCorpName" id="buildCorpName" placeholder="请输入企业名称" autocomplete="off" class="layui-input">
            </div>
        </div>
        <button class="layui-btn" lay-submit lay-filter="formDemo">查询</button>
        <button class="layui-btn" lay-submit lay-filter="formClear">清空</button>
    </div>
    <div class="layui-form-item">
        <div class="layui-inline">
            <label class="layui-form-label">验收日期：</label>
            <div class="layui-input-inline" style="width: 120px;">
                <input name="startDate" id="startDate" placeholder="开始日期" autocomplete="off" readonly="readonly" class="layui-input">
            </div>
            <div class="layui-form-mid">-</div>
            <div class="layui-input-inline" style="width: 120px;">
                <input name="endDate" id="endDate" placeholder="结束日期" autocomplete="off" readonly="readonly" class="layui-input">
            </div>
        </div>
    </div>
    <div class="layui-form-item" style="margin-bottom: 0px;">
        <div class="layui-inline">
            <label class="layui-form-label">验收类型：</label>
            <div class="layui-input-inline" style="width: 780px;">
                <input type="checkbox" name="aType" value="1" title="地基工程" lay-filter="aType">
                <input type="checkbox" name="aType" value="2" title="防水工程" lay-filter="aType">
                <input type="checkbox" name="aType" value="3" title="钢筋隐蔽工程" lay-filter="aType">
                <input type="checkbox" name="aType" value="4" title="混凝土工程" lay-filter="aType">
                <input type="checkbox" name="aType" value="5" title="屋面工程" lay-filter="aType">
                <input type="checkbox" name="aType" value="6" title="其他" lay-filter="aType">
                <input type="hidden" name="accType" id="accType">
            </div>
        </div>
    </div>
</form>
<table class="layui-hide" id="dataList" lay-filter="dataList"></table>

<script type="text/html" id="detailBtn">
    <a class="layui-btn layui-btn layui-btn-xs" lay-event="accDetail">详情</a>
</script>
<script type="text/javascript" src="/templates/user/address.js"></script>
<script type="text/javascript" src="/lib/layui/lay/modules/laydate.js"></script>
<script type="text/javascript" src="/lib/layui/layui.js"></script>
<script src="/static/js/main.js"></script>
<script>
    layui.use(['jquery', 'configureCom', 'configure', 'sessionFun', 'table', 'laydate','element'], function () {
        var $ = layui.jquery;
        var configure = layui.configure;
        var table = layui.table;
        var sessionFun = layui.sessionFun;
        var configureCom = layui.configureCom;
        var laydate = layui.laydate;
        var form=layui.form;
        var element = layui.element;
        var iframeId = configureCom.GetQueryString('iframeId');
        var accType = ['','地基工程','防水工程','钢筋隐蔽工程','混凝土工程','屋面工程','其他'];
        var cols = [[
            {field: 'cityNum', title: '所属区域', templet: function (d) {
                //区划code转中文
                if(d.provinceNum && d.cityNum && d.countyNum){
                    return convertAddressCode(d.provinceNum, d.cityNum, d.countyNum);
                }else{
                    return d.provinceNum+'-'+d.cityNum+'-'+d.countyNum;
                }
            }},
            {field: 'prjName', title: '项目名称'},
            {field: 'buildCorpName', title: '建设单位'},
            {field: 'sgCorpName', title: '施工单位'},
            {field: 'prjAreaName', title: '验收部位'},
            {field: 'accType', title: '验收类型', templet: function (d) {
                    return accType[d.accType];
                }
            },
            {field: 'accContent', title: '验收内容'},
//            {field: 'xxx', title: '验收照片'},
//            {field: 'accUserName', title: '验收人'},
            {field: 'accTime', title: '验收时间'},
            {fixed: 'right', title: '详情', toolbar: '#detailBtn'}
        ]];
        configureCom.tableRender(configure.QLY_ACCEPTANCE_LIST_API, {}, cols, 'dataList', 10, '', '');

        //每行操作
        table.on('tool(dataList)', function (obj) {
            var data = obj.data;
            sessionFun.set(configure.SESSION_QLY_ACCEPTANCE_ROW_DATA, data);
            if (obj.event === 'accDetail') {
                //新增一个Tab项 传入三个参数，分别对应其标题，tab页面的地址，还有一个规定的id，是标签中data-id的属性值
                //关于tabAdd的方法所传入的参数可看layui的开发文档中基础方法部分
//                parent.layui.element.tabAdd('zgtzdFilter', {
//                    title: '整改通知单',
//                    content: '<iframe data-frameid="'+data.insId+'" scrolling="no" frameborder="0" src="'+configure.QLY_INSPECTION_ZGTZD_HTML+'" style="width:100%;"></iframe>',
//                    id: data.insId //规定好的id
//                })
//                parent.layui.element.render('tab');

                top.layer.open({
                    type: 2,
                    title: '质量验收详情',
                    area: configureCom.Psize1,
                    content: configureCom.nocache(configure.QLY_ACCEPTANCE_DETAIL_HTML),
                    success: function (layero, index) {
//                        top.layer.full(index);
                    }
                });

            }
        });


        //开始时间-结束时间
        var start = laydate.render({
            elem: '#startDate',
            done:function(value,date){
                endMax = end.config.max;
                end.config.min = date;
                end.config.min.month = date.month -1;
            }
        });
        var end = laydate.render({
            elem: '#endDate',
            done:function(value,date){
                if($.trim(value) == ''){
                    var curDate = new Date();
                    date = {'date': curDate.getDate(), 'month': curDate.getMonth()+1, 'year': curDate.getFullYear()};
                }
                start.config.max = date;
                start.config.max.month = date.month -1;
            }
        });

        //监听市区级联
        form.on('select(cityChange)', function(data){
            var val=data.value;
            if(val){
                //加载区
                $("#countyNum").empty();
                $("#countyNum").append('<option value="">请选择</option>');
                var countyList = findCountyListByCity('130000',val);
                //遍历下拉查询返回值，并拼接到下拉框内
                $.each(countyList, function(idx, obj) {
                    $("#countyNum").append('<option value="'+obj.areaCode+'">'+obj.areaName+'</option>');
                });
            }else{
                //清空区
                $("#countyNum").empty();
                $("#countyNum").append('<option value="">请选择</option>');
            }
            //重新渲染form表单  否则动态option不生效
            form.render();
        });

        //监听问题状态
        form.on('checkbox(aType)', function(data){
            var accTypeValue = '';
            // 遍历name=aType 的多选框
            $("input:checkbox[name='aType']:checked").each(function() {
                accTypeValue = accTypeValue+ $(this).val() + ',';
            });
            if(accTypeValue){
                accTypeValue = accTypeValue.substr(0,accTypeValue.length-1)
            }
            $("#accType").val(accTypeValue);
        });

        //监听搜索
        configureCom.tableSearch();

    });

    //在新标签页中 打开页面
    function tabAdd(url,id,name) {
        //新增一个Tab项 传入三个参数，分别对应其标题，tab页面的地址，还有一个规定的id，是标签中data-id的属性值
        //关于tabAdd的方法所传入的参数可看layui的开发文档中基础方法部分
        element.tabAdd('demooooooooooooooo', {
            title: name,
            content: '<iframe data-frameid="'+id+'" scrolling="no" frameborder="0" src="'+url+'" style="width:100%;"></iframe>',
            id: id //规定好的id
        })
        element.render('tab');
    }

    /**
     * 根据省市区划编码查找区及集合
     * @param provinceNum
     * @param cityNum
     * @returns {
     */
    function findCountyListByCity(provinceNum, cityNum){
        var mallAreaList = [];
        //查找省
        for(i = 0,len=address.length; i < len; i++) {
            var province = address[i];
            if(provinceNum==province.provinceCode){
                var mallCityList = province.mallCityList;
                //查找区
                for(j = 0,len=mallCityList.length; j < len; j++) {
                    var city = mallCityList[j];
                    if(cityNum==city.cityCode){
                        mallAreaList = city.mallAreaList;
                        break;
                    }
                }
                break;
            }
        }
        return mallAreaList;
    }

    /**
     * 根据区划编码转换区划名称
     * @param provinceNum
     * @param cityNum
     * @param countyNum
     * @returns {string}
     */
    function convertAddressCode(provinceNum, cityNum, countyNum){
        var provinceName = '';
        var cityName = '';
        var countyName = '';
        //查找省
        for(i = 0,len=address.length; i < len; i++) {
            var province = address[i];
            if(provinceNum==province.provinceCode){
                provinceName = province.provinceName;
                mallCityList = province.mallCityList;
                //查找区
                for(j = 0,len=mallCityList.length; j < len; j++) {
                    var city = mallCityList[j];
                    if(cityNum==city.cityCode){
                        cityName = city.cityName;
                        mallAreaList = city.mallAreaList;
                        //查找区
                        for(k = 0,len=mallAreaList.length; k < len; k++) {
                            var county = mallAreaList[k];
                            if(countyNum==county.areaCode){
                                countyName = county.areaName;
                                break;
                            }
                        }
                        break;
                    }
                }
                break;
            }
        }
        return cityName+'-'+countyName;
    }
</script>
</body>
</html>